//
//  Student.m
//  JKRuntimeTest
//
//  Created by 王冲 on 2018/10/8.
//  Copyright © 2018年 JK科技有限公司. All rights reserved.
//

#import "Student.h"
#import "People.h"
#import <objc/runtime.h>
@implementation Student

//-(id)forwardingTargetForSelector:(SEL)aSelector{
//    
//    if (aSelector == @selector(test)) {
//
//        //return [[People alloc]init];
//        return nil;
//    }
//
//    return [super forwardingTargetForSelector:aSelector];
//}

//+(id)forwardingTargetForSelector:(SEL)aSelector{
//
//    if (aSelector == @selector(classTest)) {
//
//        return [People class];
//    }
//
//    return [super forwardingTargetForSelector:aSelector];
//}

#pragma mark 下面的代码是上面的代码不进行处理所走的方法
/**
   方法签名：返回值类型、参数类型
 */
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
    if (aSelector == @selector(test)) {
        
        // 获取其他方法(一)，会走 #pragma mark 3
        /*
          Method method = class_getInstanceMethod([People class], @selector(test));
          return [NSMethodSignature signatureWithObjCTypes:method_getTypeEncoding(method)];
        */
        
        // 下面这一句和上面2句一个意思(二) 会走 #pragma mark 3
        return [NSMethodSignature signatureWithObjCTypes:"v16@0:8"];
        
        /**
            如果返回nil 就不会再走会走 #pragma mark 3 方法了，会报错返回(doesNotRecognizeSelector)
            -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
         */
        // return nil;
    }
    return [super methodSignatureForSelector:aSelector];
}

#pragma mark 3.上面的方法不返回nil才会走
/**
   NSInvocation封装了一个方法调用，包括：方法调用者、方法名、方法参数
   anInvocation.target 方法调用者
   anInvocation.selector 方法名
   [anInvocation getArgument:NULL atIndex:0]
 */
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
//    anInvocation.target = [[MJCat alloc] init];
//    [anInvocation invoke];

    [anInvocation invokeWithTarget:[[People alloc] init]];
}



-(void)printContent{
    
    NSLog(@"[self class] = %@",[self class]);
    NSLog(@"[self superclass] = %@",[self superclass]);
    
    NSLog(@"[super class] = %@",[super class]);
    NSLog(@"[super superclass] = %@",[super superclass]);
    
}

@end
